package com.itheima.health.dao;

import com.github.pagehelper.Page;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckGroupItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 2024/7/4-23:08
 * 功能:
 */
public interface CheckGroupMapper {
    @Select("select * from t_checkgroup_checkitem where checkitem_id = #{id}")
    CheckGroupItem isExist(Integer id);
    @Insert("insert into t_checkgroup values (null, #{code}, #{name}, #{helpCode}, #{sex}, #{remark}, #{attention});")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(CheckGroup checkGroup);
    /**
     * 在中间表中指定检查组中包含的检查项
     * @param map
     */
    @Insert("insert into t_checkgroup_checkitem values (#{checkGroupId}, #{checkItemId});")
    void setCheckGroupAndCheckItem(Integer checkGroupId, Integer checkItemId);

    Page<CheckGroup>  findPage(String queryString);
    @Select("select * from t_checkgroup where id = #{id};")
    CheckGroup findById(Integer id);
    @Select("select checkitem_id from t_checkgroup_checkitem where checkgroup_id = #{checkGroupId};")
    List<Integer> findCheckItemIdsByCheckGroupId(Integer checkGroupId);

    void edit(CheckGroup checkGroup);
    @Delete("delete from t_checkgroup_checkitem where checkgroup_id = #{checkgroup_id};")
    void deleteAssociation(Integer id);
    @Select("select * from t_checkgroup_checkitem where checkgroup_id = #{id}")
    CheckGroupItem isExistGroup(Integer id);
    @Delete("delete from t_checkgroup where id = #{id};")
    Boolean deleteGroup(Integer id);
    @Select("select * from t_checkgroup;")
    List<CheckGroup> findAll();
    @Results({
            @Result(property = "checkItems", column = "id", many = @Many(select =
                    "com.itheima.health.dao.CheckItemDao.findByGroupId"))
    })
    @Select("select * from t_checkgroup where id in (select checkgroup_id from t_setmeal_checkgroup where setmeal_id = #{sid});")
    List<CheckGroup> findBySetmealId(int sid);
}
